package com.aa.studentmanage.main;

import com.aa.studentmanage.entity.LoginEntity;
import com.aa.studentmanage.entity.StudentEntity;
import com.aa.studentmanage.ui.AdminMenu;
import com.aa.studentmanage.ui.Menu;
import com.aa.studentmanage.ui.StudentMenu;
import com.aa.studentmanage.utils.InputHelper;

public class StuOperation {
    /*
    * 学生登录
    * */
    public void stuLogin(){
        LoginEntity loginEntity = Menu.loginMenu("学生");
        stuMainHome();
    }

    /*
    * 调用学生主菜单
    * */
    public void stuMainHome(){
        int stuNum = StudentMenu.personalCenter();
        switch (stuNum){
            //查看信息
            case 1:
                viewStu();
                break;
            //修改信息
            case 2:
                modifyStu();
                break;
            //返回上级
            case 0:
                System.out.println("正在返回上级");
                ProjectRun.chooseLogin();
                break;
        }
    }
    //查看信息方法
    public void viewStu(){
        System.out.print("请输入要查询的学生编号:");
        int queryStuId = InputHelper.getInt();
        StudentEntity stuInfo = null;
        if (DataInt.stuArrs.length == 0) {
            System.out.println("暂无学生数据!");
        } else {
            for (int j = 0; j < DataInt.arrIndex; j++) {
                // 用数组里面的每个学生的编号和输入的学生编号进行比对
                if (DataInt.stuArrs[j].getStuId() == queryStuId) {
                    stuInfo = DataInt.stuArrs[j];
                    break;
                }
            }
        }

        if (stuInfo == null) {
            System.out.println("没有" + queryStuId + "编号的学生!");
        } else {
            AdminMenu.studentListTitle();
            System.out.printf("%-8s", stuInfo.getStuId() + "\t");
            System.out.printf("%-8s", stuInfo.getStuName() + "\t");
            System.out.printf("%-8s", stuInfo.getStuSex() + "\t");
            System.out.printf("%-8s", stuInfo.getStuAge() + "\t");
            System.out.printf("%-8s", stuInfo.getStuClasses() + "\t");
            System.out.printf("%-8s", stuInfo.getStuAddress() + "\t");
            System.out.println();
        }
        System.out.println("1、返回上级");
        System.out.println("0、退出");
        int Num = InputHelper.getInt();
        if (Num==0){
            System.exit(0);
        }else if (Num==1){
            stuMainHome();
        }
    }
    //修改信息方法
    public void modifyStu(){
        System.out.print("请输入你的学生编号:");
        int queryStuId = InputHelper.getInt();

        StudentEntity stuInfo = null;

        if (DataInt.stuArrs.length == 0) {
            System.out.println("暂无学生数据!");
        } else {
            for (int j = 0; j < DataInt.arrIndex; j++) {
                // 用数组里面的每个学生的编号和输入的学生编号进行比对
                if (DataInt.stuArrs[j].getStuId() == queryStuId) {
                    stuInfo = DataInt.stuArrs[j];
                    break;
                }
            }
        }
        if (stuInfo == null) {
            System.out.println("没有找到" + queryStuId + "编号的学生!");
        } else {
            AdminMenu.studentListTitle();
            System.out.printf("%-8s", stuInfo.getStuId() + "\t");
            System.out.printf("%-8s", stuInfo.getStuName() + "\t");
            System.out.printf("%-8s", stuInfo.getStuSex() + "\t");
            System.out.printf("%-8s", stuInfo.getStuAge() + "\t");
            System.out.printf("%-8s", stuInfo.getStuClasses() + "\t");
            System.out.printf("%-8s", stuInfo.getStuAddress() + "\t");
            System.out.println();
        }
        System.out.println("----------------------------------------------------");
        System.out.println("请输入修改的内容");
        System.out.print("请输入新的学生姓名:");
        stuInfo.setStuName(InputHelper.getString());
        System.out.print("请输入新的学生性别:");
        stuInfo.setStuSex(InputHelper.getString());
        System.out.print("请输入新的学生年龄:");
        stuInfo.setStuAge(InputHelper.getInt());
        System.out.print("请输入新的学生班级:");
        stuInfo.setStuClasses(InputHelper.getString());
        System.out.print("请输入新的学生住址:");
        stuInfo.setStuAddress(InputHelper.getString());
        System.out.println("修改完成");
        while (true) {
            System.out.println("1、继续修改");
            System.out.println("0、返回上级");
            int Num = InputHelper.getInt();
            if (Num == 1) {
                modifyStu();
                break;
            } else if (Num == 0) {
                System.out.println("正在返回上级");
                stuMainHome();
                break;
            } else {
                System.out.println("只能选择0-1,请重新选择:");
            }
        }
    }
}
